<?php

\public\index.php
    $response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
    );

    $response->send();
上面这个 $kernel 是基于
$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);
绑定关系创建的 App\Http\Kernel 实例。


$kernel->handle() 来自继承的类 Illuminate\Foundation\Http\Kernel：
    public function handle($request)
    {
        try {
            $request->enableHttpMethodParameterOverride();

            $response = $this->sendRequestThroughRouter($request);
        } catch (Exception $e) {
            $this->reportException($e);

            $response = $this->renderException($request, $e);
        } catch (Throwable $e) {
            $this->reportException($e = new FatalThrowableError($e));

            $response = $this->renderException($request, $e);
        }

        $this->app['events']->fire('kernel.handled', [$request, $response]);

        return $response;
    }
    protected function sendRequestThroughRouter($request)
    {
        $this->app->instance('request', $request);

        Facade::clearResolvedInstance('request');

        $this->bootstrap();

        // Illuminate\Routing\Pipeline；
        return (new Pipeline($this->app))
                    ->send($request)// 返回 Pipeline 实例本身；
                    ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)// 返回 Pipeline 实例本身；
                    ->then($this->dispatchToRouter());// 返回的是 Illuminate\Http\Response 的实例；
    }

    protected function dispatchToRouter()
    {
        return function ($request) {
            $this->app->instance('request', $request);

            return $this->router->dispatch($request);
        };
    }

Illuminate\Routing\Pipeline
    class Pipeline extends Illuminate\Pipeline\Pipeline as BasePipeline

Illuminate\Pipeline\Pipeline
    class Pipeline implements Illuminate\Contracts\Pipeline\Pipeline as PipelineContract {
    public function send($passable)
    {
        // var_dump($passable);exit;// object(Illuminate\Http\Request)#38
        $this->passable = $passable;

        return $this;
    }
    public function through($pipes)
    {
        // var_dump($pipes);exit;// array(1) { [0]=> string(61) "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode" }
        $this->pipes = is_array($pipes) ? $pipes : func_get_args();

        return $this;
    }
    public function then(Closure $destination)
    {
        $firstSlice = $this->getInitialSlice($destination);

        $callable = array_reduce(
            array_reverse($this->pipes), $this->getSlice(), $firstSlice
        );

        return $callable($this->passable);
    }



\vendor\laravel\framework\src\Illuminate\Routing\Router.php
    public function dispatch(Request $request)
    {
        $this->currentRequest = $request;

        return $this->dispatchToRoute($request);
    }
    public function dispatchToRoute(Request $request)
    {
        // First we will find a route that matches this request. We will also set the
        // route resolver on the request so middlewares assigned to the route will
        // receive access to this route instance for checking of the parameters.
        $route = $this->findRoute($request);

        $request->setRouteResolver(function () use ($route) {
            return $route;
        });

        $this->events->fire(new Events\RouteMatched($route, $request));

        $response = $this->runRouteWithinStack($route, $request);

        return $this->prepareResponse($request, $response);
    }
    public function prepareResponse($request, $response)
    {
        // use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
        if ($response instanceof PsrResponseInterface) {
            // use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
            $response = (new HttpFoundationFactory)->createResponse($response);
        } elseif (! $response instanceof SymfonyResponse) {
            // use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
            // use Illuminate\Http\Response;
            $response = new Response($response);
        }

        // prepare() 方法来自继承的类，方法内最终 return $this;
        return $response->prepare($request);
    }


\vendor\symfony\http-foundation\Response.php
    public function send()
    {
        $this->sendHeaders();
        $this->sendContent();

        var_dump(function_exists('fastcgi_finish_request'));// false;
        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        } elseif ('cli' !== PHP_SAPI) {
            static::closeOutputBuffers(0, true);
        }

        return $this;
    }

    public function setContent($content)
    {
        /*
        对于控制器的方法
            如果是 echo 字符串，这里 $content 就是 null；
            如果是 return 字符串，这里 $content 就是 return 出来的字符串。
            所以，对于 echo 的情况，send() 方法时不需要的；但对于return 的，就必须要有 send()。
        */
        echo '<br/><hr/>SymfonyResponse setContent() $content<br/>';var_dump($content);echo '<hr/><br/>';
        if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
            throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
        }

        $this->content = (string) $content;

        return $this;
    }